package com.cennavi.bigdata.baotou.controller;

import com.cennavi.bigdata.baotou.service.EmergencyService;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 突发事件
 * Created by wangshipeng on 2018/10/17.
 */
@Controller
@RequestMapping("emergency")
public class EmergencyController {

    @Autowired
    private EmergencyService emergencyService;


    /**
     * 突发事件-左侧滚动条接口
     * @return
     */
    @RequestMapping(value = "/listEmergencyRoll", method = RequestMethod.GET, produces = "text/plain;charset=UTF-8")
    @ResponseBody
    public String listEmergencyRoll(@RequestParam(value = "count",defaultValue = "50",required = false) int count) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errcode",0);
        try {
            List<Map<String, Object>> list = emergencyService.listEmergencyRoll(count);
            jsonObject.put("data",list);
            jsonObject.put("errmsg","数据获取成功");
        }catch (Exception e){
            e.getMessage();
            jsonObject.put("errcode",-1);
            jsonObject.put("errmsg","数据获取异常");
        }
        return jsonObject.toString();
    }


    /**
     * 突发事件-右侧条件删选列表接口
     * @param count
     * @param startTime
     * @param endTime
     * @param type  0为全部
     * @param handletype  0全部、1已接警、2处理中、3反馈中、9已结束
     * @param influencetype  0全部、1轻微、2中度、3严重
     * @return
     */
    @RequestMapping(value = "/listEmergency", method = RequestMethod.GET, produces = "text/plain;charset=UTF-8")
    @ResponseBody
    public String listEmergency(@RequestParam(value = "count",defaultValue = "0",required = false) int count,
                                @RequestParam(value = "startTime",required = false) String  startTime,
                                @RequestParam(value = "endTime",required = false) String  endTime,
                                @RequestParam(value = "TYPE",defaultValue = "0",required = false) String  type,
                                @RequestParam(value = "HANDLETYPE",defaultValue = "0",required = false) String  handletype,
                                @RequestParam(value = "INFLUENCETYPE",defaultValue = "0",required = false) String  influencetype) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errcode",0);
        try {
            List<Map<String, Object>> list = emergencyService.listEmergency(startTime,endTime,type,handletype,influencetype,count);
            jsonObject.put("data",list);
            jsonObject.put("count",list.size());
            jsonObject.put("errmsg","数据获取成功");
        }catch (Exception e){
            e.getMessage();
            jsonObject.put("errcode",-1);
            jsonObject.put("errmsg","数据获取异常");
        }
        return jsonObject.toString();
    }

    /**
     * 突发事件-柱状图统计
     * @param statisticsType 1事件类型、2事件状态、3事件影响
     * @param startTime
     * @param endTime
     * @return
     */
    @RequestMapping(value = "/listEmergencyCount", method = RequestMethod.GET, produces = "text/plain;charset=UTF-8")
    @ResponseBody
    public String listEmergencyCount(@RequestParam(value = "statisticsType",defaultValue = "1",required = false) String statisticsType ,
                                      @RequestParam(value = "startTime",required = false) String  startTime,
                                      @RequestParam(value = "endTime",required = false) String  endTime,
                                      @RequestParam(value = "TYPE",defaultValue = "0",required = false) String  type,
                                      @RequestParam(value = "HANDLETYPE",defaultValue = "0",required = false) String  handletype,
                                      @RequestParam(value = "INFLUENCETYPE",defaultValue = "0",required = false) String  influencetype) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errcode",0);
        try {
            List<Map<String, Object>> list = emergencyService.listEmergencyCount(startTime,endTime,statisticsType,type,handletype,influencetype);
            jsonObject.put("data",list);
            jsonObject.put("errmsg","数据获取成功");
        }catch (Exception e){
            e.getMessage();
            jsonObject.put("errcode",-1);
            jsonObject.put("errmsg","数据获取异常");
        }
        return jsonObject.toString();
    }


    /**
     * 突发事件-左侧滚动条接口
     * @return
     */
    @RequestMapping(value = "/listType", method = RequestMethod.GET, produces = "text/plain;charset=UTF-8")
    @ResponseBody
    public String listType() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errcode",0);
        try {
            List<Map<String, Object>> list = emergencyService.listType();
            jsonObject.put("data",list);
            jsonObject.put("errmsg","数据获取成功");
        }catch (Exception e){
            e.getMessage();
            jsonObject.put("errcode",-1);
            jsonObject.put("errmsg","数据获取异常");
        }
        return jsonObject.toString();
    }

}
